<?php
namespace  v1;

class MyScore extends \ResourceClass{
    public $isActive = true;
    public $remark = '我的积分排行';

    public function get(array $req, array $post, &$result)
    {
        if (!isset($req['uid'])) {
            return 'require uid ';
        }
        $checkRes = $this->autoCheck($req['uid']);
        if($checkRes['code'] !== 200){
            return $checkRes['message'];
        }
        try {
            //判断type为0还是1  0总分  1 周
            $order = ' score DESC, insert_time ASC';
            if($req['type'] == \Orm\UserAccount\UserAccountClass::SCORE_TYPE_WEEK){
                $get_week_type = \Orm\UserAccount\UserAccountClass::get_week($req['week_type']);
                $order = ' '.$get_week_type.' DESC , insert_time ASC';
            }
            $user_account_list = new \Orm\UserAccount\UserAccountList();
            $user_account_list['order'] = $order;
            $user_account_list->load();
            if(count($user_account_list['lists']) > 0){
               foreach($user_account_list['lists'] as $key=>$val){
                   $result['sort'] = 0;
                   if($val['uid'] == $req['uid']){
                       $result['sort'] = $key + 1;
                       break;
                   }
               }
            }
        }catch (\Exception $e) {
            $result['sort'] = 0;
        }
    }
}